import { globalRoutes } from './index'
import { commonRoutes } from './commonRoutes'
// 流程页面
import mainBody from '@/views/pages/home/home.vue' // 流程页面
import otherPage from '@/views/pages/home/otherPage.vue' // 外链页面
import blank from '@/views/common/blank.vue' // 流程空白占位页
import { getQueryObject } from '@/utils/jcore/page'
import { findNodeDfs } from '@/utils/jcore/tree'

const routeList = globalRoutes.concat(commonRoutes)

/**
 * 路由数据配置
 * @param {*} route
 * @description 对应路由各字段数据
 */

export function getConfig(route) {
  let id = route.id
  let routeUrl = route.routeUrl
  let component = blank
  let code = route.code || ''

  let searchRoute = findNodeDfs(routeList, (item) => item.path == routeUrl)
  if (searchRoute) {
    component = searchRoute.component
  }
  let data = {}
  // 获取有参数的流程
  if (/\?/.test(routeUrl)) {
    data = getQueryObject(routeUrl)
    routeUrl = routeUrl.split('?')[0]
  }
  // 普通页面
  let routeName = routeUrl.replace('/', '')

  // 外链页面
  if (/^http/.test(routeUrl)) {
    routeName = routeUrl
    component = otherPage
  }
  
  // 父级页面
  if (routeUrl == '#' || routeUrl == '/') {
    routeName = 'p_' + route.id
  }
  return {
    hidden: route.isShow === 0,
    pid: route.pid,
    menuId: id,
    icon: route.icon,
    title: route.name,
    name: routeName,
    path: '/' + routeName,
    children: route.children,
    data,
    component,
    code
  }
}
